import * as QQAPI from "react-native-qq"
import { Jx } from "./Jx"
import { Dialog } from "./Dialog"

export class cQQios{
    static check(){
        return new Promise((resolve, reject)=>{
            Promise.all([QQAPI.isQQInstalled(), QQAPI.isQQSupportApi()])
            .then(rs=>{
                if(rs && rs[0] && rs[1]){
                    resolve(true);
                }else{
                    reject(0);
                }
            }).catch(err=>{
                reject(1);
            })
        });
    }

    static share(image, Zone){
        return new Promise((resolve)=>{
            image = {type: 'image',imageUrl: image,};
            Zone = Zone ? QQAPI.shareToQzone(image) : QQAPI.shareToQQ(image);
            Zone.then(r=>{
                console.warn(Jx.stringify(r));
                if(r.errCode == 0){
                    Dialog.toast("分享成功");
                    resolve(true);
                }else {
                    Dialog.toast("分享失效");
                    resolve(false);
                }
            }).catch(err=>{
                console.warn(Jx.stringify(err));
                if(err.errCode == -1){
                    Dialog.toast("分享取消");
                }else{
                    Dialog.toast("分享失败");
                }
                resolve(false);
            });
        })
    }
}